package api

import (
	"io/ioutil"
	"net/http"
	"net/url"
)

const BaseUrl = "http://v1.alapi.cn"

func Search(keyword string) (string, error) {
	resp, err := http.PostForm(BaseUrl+"/api/music/search", url.Values{"keyword": {keyword}, "limit": {"50"}})
	if err != nil {
		return "", err
	}
	defer func() {
		_ = resp.Body.Close()
	}()
	body, err := ioutil.ReadAll(resp.Body)
	return string(body), nil
}

func MusicDetail(musicId string) (string, error) {
	resp, err := http.PostForm(BaseUrl+"/api/music/url", url.Values{"id": {musicId}, "format": {"json"}})
	if err != nil {
		return "", err
	}
	defer func() {
		_ = resp.Body.Close()
	}()
	body, err := ioutil.ReadAll(resp.Body)
	return string(body), nil
}
